<%@ page isELIgnored="false" pageEncoding="UTF-8" contentType="text/html; UTF-8" %>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>患者管理系统</title>
    <script src="js/jquery-1.12.4.js"></script>
    <link rel="stylesheet" href="layui/css/layui.css">
    <script src="layui/layui.all.js"></script>


</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <div class="layui-col-sm12">
            <!--数据渲染表格-->
            <table id="patientTable" class="layui-table" lay-filter="patientTableFilter"></table>
        </div>
    </div>
</div>
</body>

<!-- 删除 修改的操作工具条-->
<script type="text/html" id="deleteOrUpdate">
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="delete">删除</a>
</script>

<!-- 添加、批量删除的操作工具条-->
<script type="text/html" id="andOrDeleteMulty">
    <a class="layui-btn  layui-btn-danger" lay-event="deleteMulty">批量删除</a>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <div class="layui-inline">
        <!--条件查询的 form 表格-->
        <form class="layui-form" id="searchForm" lay-filter="searchFormFilter">
            <div class="layui-form-item">
                <div class="layui-input-inline">
                    <select name="adminId" id="v_admin"></select>
                </div>
                <div class="layui-input-inline">
                    <button type="submit" class="layui-btn" lay-submit lay-filter="searchSubmitFilter">提交</button>
                </div>
            </div>
        </form>
    </div>
</script>

<script type="text/javascript">
    layui.use(['table', 'form', 'layer'], function () {

        var table = layui.table;
        var form = layui.form;

        table.render({
            elem: '#patientTable',
            url: '/cmfz/adminLog/getAll',
            page: false,
            toolbar: '#andOrDeleteMulty',
            cols: [[
                {type: 'checkbox'},
                {title: '日志编号', field: 'logId'},
                {title: '记录姓名', field: 'logDate'},
                {title: '管理员姓名', templet: '<div>{{d.admin.adminName}}</div>'},
                {title: '日志内容', field: 'logContent'},
                {title: '操作类别', field: 'logType'},
                {title: '登录IP', field: 'logIp'},
                {title: '操作', toolbar: '#deleteOrUpdate'},
            ]]
        });

//==================批量删除事件，打开弹出层 开始========================================
        table.on('toolbar(patientTableFilter)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            if (obj.event == 'deleteMulty') {
                var arr = checkStatus.data; //获取选择的数据
                var ids = [];
                for (var i = 0; i < arr.length; i++) {
                    ids.push(arr[i].logId)
                }
                if (arr.length == 0) {
                    layer.msg('至少选择一个要删除的选项')
                    return;
                }

                $.ajax({
                    url: '/cmfz/adminLog/delBulk',
                    data: 'ids=' + ids,
                    success: function (msg) {
                        if (msg) table.reload('patientTable');
                        else {
                            layer.msg("删除失败");
                            table.reload('patientTable');
                        }
                    }
                });
            }
        });
//==================批量删除事件，打开弹出层 结束========================================


//===================删除 事件绑定开始=========================================
        table.on('tool(patientTableFilter)', function (obj) {
            if (obj.event == "delete") {
                layer.confirm("确认要删除吗？", function (index) {
                    $.ajax({
                        url: '/cmfz/adminLog/delById',
                        data: "logId=" + obj.data.logId,
                        dataType: "json",
                        success: function (msg) {
                            if (msg) {
                                table.reload('patientTable');
                                layer.close(index);
                            } else layer.msg("删除异常")
                        }
                    });
                });
            }
        })

        $.ajax({
            url: '/cmfz/admin/getAll',
            dataType: 'json',
            success: function (result) {
                if (result) {
                    console.log(result.data)
                    var v_html = "<option value=0>请选择管理员名字</option>";
                    var arr = result.data
                    for (var i in arr) {
                        v_html += "<option value=" + arr[i].adminId + ">" + arr[i].adminName + "</option>";
                    }
                    $("#v_admin").html(v_html);
                    form.render();
                }
            }
        });
//===================删除 事件绑定结束===============================================


        form.on('submit(searchSubmitFilter)', function (data) {
            /* console.log(data.elem) //被执行事件的元素DOM对象，一般为button对象
             console.log(data.form) //被执行提交的form对象，一般在存在form标签时才会返回
             console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}*/

            console.log(data.field.departName)
            table.reload('patientTable', {
                where: {
                    guruNickname: data.field.guruNickname
                },
                page: {
                    curr: 1
                }
            })
            return false;
        })

    });


</script>
</html>